package com.app.twth.ui.lpnphoto;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.app.twth.databinding.ItemLpnphotoDetailListBinding;
import com.app.twth.interfaces.MyOnClickListener;

import java.util.ArrayList;
import java.util.List;


public class LPNPhotoDetailAdapter extends RecyclerView.Adapter<LPNPhotoDetailAdapter.MyViewHolder> {
    private int index = -1;
    private Context mContext;
    private LayoutInflater mInflater;
    private MyOnClickListener locationListener;
    private List<LPNPhotoDetails> data = new ArrayList<>();

    public LPNPhotoDetailAdapter(Context mContext, List<LPNPhotoDetails> data, MyOnClickListener locationListener) {
        this.mContext = mContext;
        this.data = data;
        this.mInflater = LayoutInflater.from(mContext);
        this.locationListener = locationListener;
    }

    public void setData(List<LPNPhotoDetails> data, int index) {
        this.data = data;
        this.index = index;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(ItemLpnphotoDetailListBinding.inflate(mInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ItemLpnphotoDetailListBinding itemBinding;

        public MyViewHolder(ItemLpnphotoDetailListBinding itemBinding) {
            super(itemBinding.getRoot());
            this.itemBinding = itemBinding;
        }

        public void setData(int position) {
            itemView.setTag(position);
            LPNPhotoDetails tallyLPN = data.get(position);
            itemBinding.tvSku.setText(tallyLPN.getIbLpn() + "");
            itemBinding.tvTallyQty.setText(tallyLPN.getSku() + "");
            itemBinding.tvLpnQty.setText(tallyLPN.getQty() + "");
        }
    }

}
